/**
 * Copyright (c) 2023 - present All rights reserved.
 * <p>
 * Reprinted has been protected by the copyright laws.
 */

package cn.myxl.smart.devkit.commit.model;

import javax.swing.table.AbstractTableModel;
import java.util.List;

/**
 * @author alan.yang.zhang
 * @date 2023-11-15 14:03
 */

public class CommitTypeTableModel extends AbstractTableModel {
	private final List<CommitType> commitTypeList;

	public CommitTypeTableModel(List<CommitType> commitTypeList) {
		this.commitTypeList = commitTypeList;
	}

	@Override
	public int getRowCount() {
		return this.commitTypeList.size();
	}

	@Override
	public int getColumnCount() {
		return 2;
	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		return String.class;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		CommitType commitType = this.commitTypeList.get(rowIndex);

		switch (columnIndex) {
			case 0:
				return commitType.getTitle();
			case 1:
				return commitType.getDescription();
		}

		return null;
	}

	@Override
	public String getColumnName(int columnIndex) {
		switch (columnIndex) {
			case 0:
				return "title";
			case 1:
				return "description";
		}
		return null;
	}

	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return false;
	}
}
